package com.cn.wanxi.service.impl;

import com.cn.wanxi.dao.NewsDao;
import com.cn.wanxi.dao.impl.NewsImpl;
import com.cn.wanxi.model.NewsModel;
import com.cn.wanxi.model.PageModel;
import com.cn.wanxi.model.ResultModel;
import com.cn.wanxi.service.INewsService;

import java.util.List;

public class NewsServiceImpl implements INewsService {
    @Override
    public ResultModel add(NewsModel newsModel) {
        NewsDao newsDao = new NewsImpl();
        ResultModel resultModel = new ResultModel();
        resultModel.setResult(newsDao.add(newsModel) == 1 ? "新增成功" : "新增失败");
        return resultModel;
    }

    @Override
    public ResultModel findAll(NewsModel newsModel, PageModel pageModel) {
        ResultModel resultModel=new ResultModel();
        resultModel.setCode("200");
        resultModel.setResult("查詢成功");
        NewsDao newsDao = new NewsImpl();
        resultModel.setCount(newsDao.getCount(newsModel));
        List<NewsModel> list=newsDao.findAll(newsModel,pageModel);
        resultModel.setObject(list);
        return resultModel;
    }

    @Override
    public List<NewsModel> getList() {
        NewsDao newsDao = new NewsImpl();
        return newsDao.getList();
    }
}
